package com.fitz.remote.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HeartbeatClientHandler extends ChannelInboundHandlerAdapter implements ITriggerHandler {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
             if (event.state().equals(IdleState.WRITER_IDLE)) {
//                 PingPacket pingPacket = new PingPacket();
//                 pingPacket.setMessage("ping");
//                ctx.writeAndFlush(pingPacket);
                log.info("ping");
            }else if (event.state().equals(IdleState.READER_IDLE)) {
                log.info("长时间没收到数据");
            } else if (event.state().equals(IdleState.ALL_IDLE)) {
                log.info("ALL");
            }
        }
    }
}
